using System;
using System.IO;
using System.Text.Json;

namespace WinformTemplete.Common
{
    public static class ConfigManager
    {
        private static readonly string ConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
        private static dynamic _config;

        static ConfigManager()
        {
            if (File.Exists(ConfigPath))
            {
                string json = File.ReadAllText(ConfigPath);
                _config = JsonSerializer.Deserialize<dynamic>(json);
            }
            else
            {
                _config = new { };
            }
        }

        public static T GetValue<T>(string key, T defaultValue = default)
        {
            try
            {
                return (T)_config.GetProperty(key).GetValue();
            }
            catch
            {
                return defaultValue;
            }
        }
    }
} 